#ifndef CTEXTTABLE_H
#define CTEXTTABLE_H

#include <QObject>
#include "AbsTable.h"
#include <QVariantList>

class CTextTable : public AbsTable
{
    Q_OBJECT
public:
    explicit CTextTable(QString strTableName,QStringList strListColumnNames,QObject *parent = nullptr);

    virtual bool createTable();

public:
    template<class TemplateRowStruct>
    bool addRow(TemplateRowStruct st)
    {
        return addRow(st.getData());
    }
    template<class TemplateRowStruct>
    bool updateRow(TemplateRowStruct st)
    {
        return updateRow(st.getData());
    }
    template<class TemplateRowStruct>
    TemplateRowStruct queryRow(QString strId)
    {
        TemplateRowStruct st;
        st.loadData(queryRow(strId));
        return st;
    }
    template<class TemplateRowStruct>
    QVector<TemplateRowStruct> queryAll()
    {
        QVector<QVariantList> varRows = queryAll();
        QVector<TemplateRowStruct> vecStructs;
        foreach(QVariantList varList,varRows){
                TemplateRowStruct stResult;
                stResult.loadData(varList);
                vecStructs.push_back(stResult);
        }
        return vecStructs;
    }
public:
    bool addRow(QVariantList varList);
    bool deleteRow(QString strId);
    bool updateRow(QVariantList varList);
    bool updateColumn(QString strId, int nColumnIndex, QString strColumnVal);
    QVariantList queryRow(QString strId);
    QVector<QVariantList> queryAll();
protected:
    QStringList m_strListColumnNames;
};

#endif // CTEXTTABLE_H
